home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Extras / AutoUpdateIt / AutoUpdateIt.au3
Text File  |  2007-09-08  |  31KB  |  668 lines

  1. #NoTrayIcon
  2. ; =======================================================================
  3. ; AutoUpdateIt
  4. ; Original by Rob Saunders
  5. ; Modifications by JPM/strik3r0475/erebus
  6. ;
  7. ; Command Line Options:
  8. ;  - AutoUpdateIt.au3 [/release | /beta | /prebeta] [/silent] [/noproxy]
  9. ;    - /release   Download latest release
  10. ;    - /beta      Download latest beta
  11. ;    - /prebeta   Download latest prebeta
  12. ;    - /silent    Silently auto-install (resets all settings)
  13. ;    - /noproxy   Use direct internet access (no IE proxy)
  14. ;
  15. ; History:
  16. ;  - 1.40 - Fixed a bug where the updater crashed if AU3 was not already installed (by erebus)
  17. ;         - Fixed some display bugs, occured if AU3 was not already installed (by erebus)
  18. ;         - Re-added the installation paths on the GUI; tiny but useful (by erebus)
  19. ;         - Added the /noproxy command line switch to allow direct internet access (by erebus)
  20. ;         - Added a menu option to disable/enable the use of IE's proxy (by erebus)
  21. ;  - 1.37 - Change Alpha to Pre-Beta (by JPM)
  22. ;  - 1.36 - Display current Beta (by strik3r0475)
  23. ;  - 1.35 - Fixed some display bugs
  24. ;  - 1.34 - Display Alpha release if available
  25. ;         - Command line parameters added /alpha to check for latest alpha
  26. ;  - 1.33 - Added Retry/Cancel msgbox when cannot connect to receive update file
  27. ;         - Added Progress bar for non-WinXP users
  28. ;  - 1.32 - Changed _CompareVersions again (integer comparison now)
  29. ;  - 1.31 - Rewrote _ClipPath again
  30. ;  - 1.30 - Rewrote a few UDFs (_CompareVersions, _ClipPath)
  31. ;         - Underscored all UDF names
  32. ;         - Removed a misplaced 'Then' screwing up command line options
  33. ;  - 1.21 - Stupid bug fixed (ignored version check for /beta command)
  34. ;         - CompareVersions function works properly now (was seeing 3.0.103.173 as newer than 3.1.0.1)
  35. ;  - 1.20 - Command line parameters added
  36. ;           - /release to check for latest public release
  37. ;           - /beta to check for latest beta
  38. ;           - /silent to install silently (you will lose your compiler and file settings)
  39. ;  - 1.11 - Starts the download when you press one of the download
  40. ;           buttons, resulting in pre-downloading while you choose
  41. ;           where to save the file
  42. ;         - Default name for Beta download includes full version string
  43. ;         - Deletes "au3_update.dat" from temp files after loading data
  44. ;  - 1.10 - Displays release date
  45. ;         - Changed layout of buttons / groups
  46. ;         - Slightly modified error message when server inaccessible
  47. ;  - 1.00 - "Release" / given a version number
  48. ;
  49. ; Forum Threads:
  50. ;  - http://www.autoitscript.com/forum/index.ph...view=getnewpost
  51. ;  - http://www.autoitscript.com/forum/index.ph...view=getnewpost
  52. ;
  53. ; =======================================================================
  54. #Include <GUIConstants.au3>
  55. ; ========================================
  56. ; Predefine variables
  57. ; ========================================
  58. Global Const $s_Title = 'AutoUpdateIt'
  59. Global Const $s_Version = '1.40'
  60. Global Const $s_DatFile = 'http://www.autoitscript.com/autoit3/files/beta/update.dat'
  61. Global Const $b_Download_UpdateDat = 1
  62. Global Const $s_DatFile_Local = @TempDir & '\au3_update.dat'
  63. Global Const $s_Au3UpReg = 'HKCU\Software\AutoIt v3\AutoUpdateIt'
  64. Global $i_DownSize, $s_DownPath, $s_DownTemp, $s_DownFolder
  65. Global $i_DatFileLoaded, $i_ValidAu3Path, $i_DnInitiated
  66. Global $s_AutoUpdate, $i_SilentInstall
  67. Global $s_CurrDate
  68. Dim $s_ReleaseVer, $s_ReleaseFile, $i_ReleaseSize, $i_ReleaseDate, $s_ReleasePage
  69. Dim $s_LatestBetaVer, $s_BetaFile, $i_BetaSize, $i_BetaDate, $s_BetaPage, $s_CurrBetaVer, $s_CurrBetaDate
  70. Dim $s_PreBetaVer, $s_PreBetaFile, $i_PreBetaSize, $i_PreBetaDate, $s_PreBetaPage
  71. ; ========================================
  72. ; Read registry settings
  73. ; ========================================
  74. Global $s_DefDownDir = RegRead($s_Au3UpReg, 'DownloadDir')
  75. If @error Then
  76.     $s_DefDownDir = @DesktopDir
  77. EndIf
  78. Global $s_Au3Path = RegRead('HKLM\Software\AutoIt v3\AutoIt', 'InstallDir')
  79. If Not @error And FileExists($s_Au3Path & '\AutoIt3.exe') Then
  80.     $s_CurrVer = FileGetVersion($s_Au3Path & "\AutoIt3.exe")
  81.     $s_CurrDate = _FriendlyDate(FileGetTime($s_Au3Path & "\AutoIt3.exe", 0, 1))
  82. Else
  83.     $s_Au3Path = 'Installation not found'
  84.     $s_CurrVer = 'Unavailable'
  85.     $s_CurrDate = 'Unavailable'
  86. EndIf
  87. Global $s_BetaPath = RegRead('HKLM\Software\AutoIt v3\AutoIt', 'betaInstallDir')
  88. If Not @error And FileExists($s_BetaPath & '\AutoIt3.exe') Then
  89.     $s_CurrBetaVer = FileGetVersion($s_BetaPath & "\AutoIt3.exe")
  90.     $s_CurrBetaDate = _FriendlyDate(FileGetTime($s_BetaPath & "\AutoIt3.exe", 0, 1))
  91. Else
  92.     $s_BetaPath = 'Installation not found'
  93.     $s_CurrBetaVer = 'Unavailable'
  94.     $s_CurrBetaDate = 'Unavailable'
  95. EndIf
  96. ; ========================================
  97. ; Check for command line parameters
  98. ; ========================================
  99. If _StringInArray($CmdLine, '/noproxy') Then HttpSetProxy(1)
  100. If _StringInArray($CmdLine, '/release') Or _StringInArray($CmdLine, '/beta') Or _StringInArray($CmdLine, '/prebeta') Then
  101.     Opt('TrayIconHide', 0)
  102.     _Status('Checking for updates')
  103.     InetGet($s_DatFile, $s_DatFile_Local, 1)
  104.     If @InetGetBytesRead = -1 Then
  105.         _Status('Could not connect to site', 'Please check your connection and try again')
  106.         Sleep(4000)
  107.         Exit
  108.     EndIf
  109.     _LoadUpdateData()
  110.     If _StringInArray($CmdLine, '/release') And _CompareVersions($s_ReleaseVer, $s_CurrVer) Then
  111.         $s_AutoUpdate = $s_ReleaseFile
  112.         $s_DownTemp = @TempDir & '\autoit-v3-setup.exe'
  113.         $i_DownSize = $i_ReleaseSize
  114.     ElseIf _StringInArray($CmdLine, '/beta') And _CompareVersions($s_LatestBetaVer, $s_CurrVer) Then
  115.         $s_AutoUpdate = $s_BetaFile
  116.         $s_DownTemp = @TempDir & '\autoit-v' & $s_LatestBetaVer & '.exe'
  117.         $i_DownSize = $i_BetaSize
  118.     ElseIf _StringInArray($CmdLine, '/prebeta') And _CompareVersions($s_PreBetaVer, $s_CurrVer) Then
  119.         $s_AutoUpdate = $s_PreBetaFile
  120.         $s_DownTemp = @TempDir & '\autoit-v' & $s_PreBetaVer & '.exe'
  121.         $i_DownSize = $i_PreBetaSize
  122.     EndIf
  123.     If $s_AutoUpdate Then
  124.         InetGet($s_AutoUpdate, $s_DownTemp, 1, 1)
  125.         $s_DownSize = Round($i_ReleaseSize / 1024) & ' KB'
  126.         While @InetGetActive
  127.             _Status('Downloading update', '', @InetGetBytesRead, $i_DownSize)
  128.         WEnd
  129.         _Status('Download Complete', 'Launching install')
  130.         Sleep(1000)
  131.         If _StringInArray($CmdLine, '/silent') Then
  132.             _Start('"' & $s_DownTemp & '" /S')
  133.         Else
  134.             _Start('"' & $s_DownTemp & '"')
  135.         EndIf
  136.     Else
  137.         _Status('No new versions available')
  138.         Sleep(1000)
  139.     EndIf
  140.     Exit
  141. EndIf
  142. ; ========================================
  143. ; GUI - Main Application
  144. ; ========================================
  145. Opt("GuiResizeMode", $GUI_DOCKALL)
  146. $gui_Main = GUICreate($s_Title, 350, 310 + 20)
  147. $me_Mn_Help = GUICtrlCreateMenu('&Help')
  148. $me_Mn_Proxy = GUICtrlCreateMenuItem('Disable IE''s &proxy server', $me_Mn_Help)
  149. $me_Mn_VisitSite = GUICtrlCreateMenuItem('&Visit the AutoIt3 Website', $me_Mn_Help)
  150. $me_Mn_About = GUICtrlCreateMenuItem('&About', $me_Mn_Help)
  151. $lb_separator=GUICtrlCreateLabel('', 0, 0, 350, 2, $SS_SUNKEN)
  152. $gr_Instal_Details = GUICtrlCreateGroup('Current Installation Details', 5, 5, 340, 70)
  153. GUICtrlCreateLabel('Production Version: ' & $s_CurrVer, 15, 25, 160, 15)
  154. GUICtrlCreateLabel('Date: ' & $s_CurrDate, 15, 40, 160, 15)
  155. GUICtrlCreateLabel('Path: ' & $s_Au3Path, 15, 55, 160, 15)
  156. GUICtrlSetFont(-1, 6)
  157. GUICtrlCreateLabel('Beta Version: ' & $s_CurrBetaVer, 190, 25, 150, 15)
  158. GUICtrlCreateLabel('Date: ' & $s_CurrBetaDate, 190, 40, 150, 15)
  159. GUICtrlCreateLabel('Path: ' & $s_BetaPath, 190, 55, 150, 15)
  160. GUICtrlSetFont(-1, 6)
  161. $gr_Mn_Release = GUICtrlCreateGroup('Latest Public Release', 5, 85, 165, 60)
  162. $lb_Mn_ReleaseVer = GUICtrlCreateLabel('Version: Loading...', 15, 105, 145, 15)
  163. $lb_Mn_ReleaseDate = GUICtrlCreateLabel('Date: Loading...', 15, 120, 145, 15)
  164. $gr_Mn_Beta = GUICtrlCreateGroup('Latest Beta', 180, 85, 165, 60)
  165. $lb_Mn_BetaVer = GUICtrlCreateLabel('Version: Loading...', 190, 105, 145, 15)
  166. $lb_Mn_BetaDate = GUICtrlCreateLabel('Date: Loading...', 190, 120, 145, 15)
  167. $gr_Mn_PreBeta = GUICtrlCreateGroup('Latest Pre-Beta', 180 + 175, 85, 165, 60)
  168. $lb_Mn_PreBetaVer = GUICtrlCreateLabel('Version: Loading...', 190 + 175, 105, 145, 15)
  169. $lb_Mn_PreBetaDate = GUICtrlCreateLabel('Date: Loading...', 190 + 175, 120, 145, 15)
  170. GUIStartGroup()
  171. $ra_Mn_DoneNotify = GUICtrlCreateRadio('&Notify when download complete', 5, 155, 340, 15)
  172. $ra_Mn_DoneRun = GUICtrlCreateRadio('&Autorun install when download complete', 5, 175, 340, 15)
  173. ; Check default done option
  174. If RegRead($s_Au3UpReg, 'DoneOption') = 'Run' Then
  175.     GUICtrlSetState($ra_Mn_DoneRun, $GUI_CHECKED)
  176. Else
  177.     GUICtrlSetState($ra_Mn_DoneNotify, $GUI_CHECKED)
  178. EndIf
  179. $bt_Mn_Close = GUICtrlCreateButton('&Close', 10, 275, 330, 25)
  180. ; ========================================
  181. ; Control Set - Download Buttons
  182. ; ========================================
  183. $bt_Mn_ReleaseDl = GUICtrlCreateButton('Download Public &Release', 5, 195, 165, 30)
  184. GUICtrlSetState(-1, $GUI_DISABLE)
  185. $lb_Mn_ReleaseSize = GUICtrlCreateLabel('Size: Loading...', 5, 230, 165, 15, $SS_CENTER)
  186. $lb_Mn_ReleasePage = GUICtrlCreateLabel('Visit Download Page', 5, 245, 165, 15, $SS_CENTER)
  187. GUICtrlSetState(-1, $GUI_DISABLE)
  188. GUICtrlSetFont(-1, 9, 400, 4)
  189. GUICtrlSetColor(-1, 0x0000ff)
  190. GUICtrlSetCursor(-1, 0)
  191. $bt_Mn_BetaDl = GUICtrlCreateButton('Download &Beta', 180, 195, 165, 30)
  192. GUICtrlSetState(-1, $GUI_DISABLE)
  193. $lb_Mn_BetaSize = GUICtrlCreateLabel('Size: Loading...', 180, 230, 165, 15, $SS_CENTER)
  194. $lb_Mn_BetaPage = GUICtrlCreateLabel('Visit Download Page', 180, 245, 165, 15, $SS_CENTER)
  195. GUICtrlSetState(-1, $GUI_DISABLE)
  196. GUICtrlSetFont(-1, 9, 400, 4)
  197. GUICtrlSetColor(-1, 0x0000ff)
  198. GUICtrlSetCursor(-1, 0)
  199. $bt_Mn_PreBetaDl = GUICtrlCreateButton('Download &Pre-Beta', 180 + 175, 195, 165, 30)
  200. GUICtrlSetState(-1, $GUI_DISABLE)
  201. $lb_Mn_PreBetaSize = GUICtrlCreateLabel('Size: Loading...', 180 + 175, 230, 165, 15, $SS_CENTER)
  202. $lb_Mn_PreBetaPage = GUICtrlCreateLabel('Visit Download Page', 180 + 175, 245, 165, 15, $SS_CENTER)
  203. GUICtrlSetState(-1, $GUI_DISABLE)
  204. GUICtrlSetFont(-1, 9, 400, 4)
  205. GUICtrlSetColor(-1, 0x0000ff)
  206. GUICtrlSetCursor(-1, 0)
  207. $a_DownButtons = StringSplit($bt_Mn_ReleaseDl & '.' & _
  208.         $lb_Mn_ReleaseSize & '.' & _
  209.         $lb_Mn_ReleasePage & '.' & _
  210.         $bt_Mn_BetaDl & '.' & _
  211.         $lb_Mn_BetaSize & '.' & _
  212.         $lb_Mn_BetaPage & '.' & _
  213.         $bt_Mn_PreBetaDl & '.' & _
  214.         $lb_Mn_PreBetaSize & '.' & _
  215.         $lb_Mn_PreBetaPage, '.')
  216. ; ========================================
  217. ; Control Set - Download Display
  218. ; ========================================
  219. $lb_Mn_DwnToTtl = GUICtrlCreateLabel('Downloading to:', 5, 195, 290, 15, $SS_LEFTNOWORDWRAP)
  220. $lb_Mn_DwnToTxt = GUICtrlCreateLabel('', 5, 210, 290, 15, $SS_LEFTNOWORDWRAP)
  221. $pg_Mn_Progress = GUICtrlCreateProgress(5, 225, 340, 20)
  222. $lb_Mn_Progress = GUICtrlCreateLabel('', 5, 250, 290, 15)
  223. $bt_Mn_OpenFile = GUICtrlCreateButton('&Open', 105, 275, 75, 25)
  224. GUICtrlSetState(-1, $GUI_DISABLE)
  225. $bt_Mn_OpenFolder = GUICtrlCreateButton('Open &Folder', 185, 275, 75, 25)
  226. GUICtrlSetState(-1, $GUI_DISABLE)
  227. $a_DownDisplay = StringSplit($lb_Mn_DwnToTtl & '.' & _
  228.         $lb_Mn_DwnToTxt & '.' & _
  229.         $pg_Mn_Progress & '.' & _
  230.         $lb_Mn_Progress & '.' & _
  231.         $bt_Mn_OpenFile & '.' & _
  232.         $bt_Mn_OpenFolder, '.')
  233. _GuiCtrlGroupSetState($a_DownDisplay, $GUI_HIDE)
  234. ; ========================================
  235. ; GUI - About
  236. ; ========================================
  237. $gui_About = GUICreate('About', 300, 120, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), -1, $gui_Main)
  238. GUICtrlCreateLabel($s_Title & ' v' & $s_Version & ' - The AutoIt3 Update Utility' & @LF & _
  239.         @LF & _
  240.         'This application is a utility for easily receiving the most ' & _
  241.         'recent public release or beta version of AutoIt3 available. ' & _
  242.         'It was written in AutoIt3 script by Rob Saunders.', 5, 5, 290, 75)
  243. $lb_Ab_VisitSite = GUICtrlCreateLabel('Visit the AutoIt Website', 5, 100, 145, 15)
  244. GUICtrlSetFont(-1, 9, 400, 4)
  245. GUICtrlSetColor(-1, 0x0000ff)
  246. GUICtrlSetCursor(-1, 0)
  247. GUICtrlSetTip(-1, 'http://www.autoitscript.com')
  248. ;$lb_Ab_ContactAuthor = GUICtrlCreateLabel('Contact Rob Saunders', 5, 100, 145, 15)
  249. ;GUICtrlSetFont(-1, 9, 400, 4)
  250. ;GUICtrlSetColor(-1, 0x0000ff)
  251. ;GUICtrlSetCursor(-1, 0)
  252. ;GUICtrlSetTip(-1, 'rksaunders@gmail.com')
  253. $bt_Ab_Close = GUICtrlCreateButton('&Close', 220, 90, 75, 25)
  254. ; ========================================
  255. ; Application start
  256. ; ========================================
  257. ; Show Main Window
  258. If _StringInArray($CmdLine, '/noproxy') Then GUICtrlSetState($me_Mn_Proxy, $GUI_CHECKED)
  259. GUISetState(@SW_SHOW, $gui_Main)
  260. ; Download update data file
  261. If $b_Download_UpdateDat Then
  262.     InetGet($s_DatFile, $s_DatFile_Local, 1, 1)
  263. Else
  264.     FileCopy(@ScriptDir & '\update.dat',$s_DatFile_Local) ; to test locally
  265. EndIf
  266. ; Harness GUI Events
  267. While 1
  268.     $a_GMsg = GUIGetMsg(1)
  269.     If Not @InetGetActive And Not $i_DatFileLoaded Then
  270.         If @InetGetBytesRead = -1 AND $b_Download_UpdateDat Then
  271.             $i_Res = MsgBox(5 + 16 + 8192, 'Error', 'Error connecting to server.' & @LF & _
  272.                     'Please verify the following:' & @LF & _
  273.                     ' - You can connect to the internet' & @LF & _
  274.                     ' - You can access the site http://www.AutoItScript.com' & @LF & _
  275.                     ' - Your firewall is not blocking internet access to this program')
  276.             If $i_Res = 4 Then
  277.                 InetGet($s_DatFile, $s_DatFile_Local, 1, 1)
  278.             Else
  279.                 Exit
  280.             EndIf
  281.         Else
  282.             _LoadUpdateData()
  283.             If $s_PreBetaVer <> '' Then
  284.                 If _CompareVersions(StringTrimRight($s_PreBetaVer, 1), $s_LatestBetaVer) > 0 Then
  285.                     $pos = WinGetPos($s_Title)
  286.                     WinMove($s_Title, "", $pos[0], $pos[1], $pos[2] + 175, $pos[3])
  287.                     GUICtrlSetPos($lb_separator, 0, 0, 350 + 175, 2)
  288.                     GUICtrlSetPos($gr_Instal_Details, 5, 5, 340 + 175, 75)
  289.                     GUICtrlSetPos($bt_Mn_Close, 10, 275, 330 + 175, 25)
  290.                     GUICtrlSetPos($lb_Mn_DwnToTtl, 5, 195, 290 + 175, 15)
  291.                     GUICtrlSetPos($lb_Mn_DwnToTxt, 5, 210, 290 + 175, 15)
  292.                     GUICtrlSetPos($pg_Mn_Progress, 5, 225, 340 + 175, 20)
  293.                     GUICtrlSetPos($lb_Mn_Progress, 5, 250, 290 + 175, 15)
  294.                     GUICtrlSetPos($bt_Mn_OpenFile, 105 + 175, 275, 75, 25)
  295.                     GUICtrlSetPos($bt_Mn_OpenFolder, 185 + 175, 275, 75, 25)
  296.                 Else
  297.                     $s_PreBetaVer = ''
  298.                 EndIf
  299.             EndIf
  300.             $i_ReleaseSizeKB = Round($i_ReleaseSize / 1024)
  301.             $i_BetaSizeKB = Round($i_BetaSize / 1024)
  302.             $i_PreBetaSizeKB = Round($i_PreBetaSize / 1024)
  303.             If _CompareVersions($s_ReleaseVer, $s_CurrVer) Then
  304.                 GUICtrlSetData($gr_Mn_Release, 'Latest Public Release *New*')
  305.                 GUICtrlSetColor($gr_Mn_Release, 0x0000ff)
  306.             EndIf
  307.             GUICtrlSetData($lb_Mn_ReleaseVer, 'Version: ' & $s_ReleaseVer)
  308.             If _CompareVersions($s_LatestBetaVer, $s_CurrBetaVer) Then
  309.                 GUICtrlSetData($gr_Mn_Beta, 'Latest Beta *New*')
  310.                 GUICtrlSetColor($gr_Mn_Beta, 0x0000ff)
  311.             EndIf
  312.             GUICtrlSetData($lb_Mn_BetaVer, 'Version: ' & $s_LatestBetaVer)
  313.             If _CompareVersions($s_PreBetaVer, $s_CurrVer) Then
  314.                 GUICtrlSetData($gr_Mn_PreBeta, 'Latest pre-Beta *New*')
  315.                 GUICtrlSetColor($gr_Mn_PreBeta, 0x0000ff)
  316.             EndIf
  317.             GUICtrlSetData($lb_Mn_PreBetaVer, 'Version: ' & $s_PreBetaVer)
  318.             GUICtrlSetData($lb_Mn_ReleaseDate, 'Date: ' & _FriendlyDate($i_ReleaseDate))
  319.             GUICtrlSetData($lb_Mn_BetaDate, 'Date: ' & _FriendlyDate($i_BetaDate))
  320.             GUICtrlSetData($lb_Mn_PreBetaDate, 'Date: ' & _FriendlyDate($i_PreBetaDate))
  321.             GUICtrlSetData($lb_Mn_ReleaseSize, 'Size: ' & $i_ReleaseSizeKB & ' KB')
  322.             GUICtrlSetData($lb_Mn_BetaSize, 'Size: ' & $i_BetaSizeKB & ' KB')
  323.             GUICtrlSetData($lb_Mn_PreBetaSize, 'Size: ' & $i_PreBetaSizeKB & ' KB')
  324.             GUICtrlSetTip($lb_Mn_ReleasePage, $s_ReleasePage)
  325.             GUICtrlSetTip($lb_Mn_BetaPage, $s_BetaPage)
  326.             GUICtrlSetTip($lb_Mn_PreBetaPage, $s_PreBetaPage)
  327.             GUICtrlSetState($bt_Mn_ReleaseDl, $GUI_ENABLE)
  328.             GUICtrlSetState($bt_Mn_BetaDl, $GUI_ENABLE)
  329.             GUICtrlSetState($bt_Mn_PreBetaDl, $GUI_ENABLE)
  330.             GUICtrlSetState($lb_Mn_ReleasePage, $GUI_ENABLE)
  331.             GUICtrlSetState($lb_Mn_BetaPage, $GUI_ENABLE)
  332.             GUICtrlSetState($lb_Mn_PreBetaPage, $GUI_ENABLE)
  333.             $i_DatFileLoaded = 1
  334.         EndIf
  335.     EndIf
  336.     If $i_DnInitiated Then
  337.         If @InetGetActive Then
  338.             $i_DnPercent = Int(@InetGetBytesRead / $i_DownSize * 100)
  339.             $s_DnBytes = Round(@InetGetBytesRead / 1024) & ' KB'
  340.             $s_DnSize = Round($i_DownSize / 1024) & ' KB'
  341.             GUICtrlSetData($pg_Mn_Progress, $i_DnPercent)
  342.             GUICtrlSetData($lb_Mn_Progress, 'Download Progress: ' & $i_DnPercent & '% (' & $s_DnBytes & ' of ' & $s_DnSize & ')')
  343.         Else
  344.             GUICtrlSetData($pg_Mn_Progress, 100)
  345.             If Not FileMove($s_DownTemp, $s_DownPath, 1) Then
  346.                 MsgBox(16 + 8192, 'Error', 'Error moving file.')
  347.                 GUICtrlSetData($lb_Mn_Progress, 'Error')
  348.             Else
  349.                 If GUICtrlRead($ra_Mn_DoneRun) = $GUI_CHECKED Then
  350.                     _Start('"' & $s_DownPath & '"')
  351.                     Exit
  352.                 Else
  353.                     GUICtrlSetData($lb_Mn_Progress, 'Download Complete!')
  354.                     GUICtrlSetData($bt_Mn_Close, '&Close')
  355.                     GUICtrlSetState($bt_Mn_OpenFile, $GUI_ENABLE)
  356.                     GUICtrlSetState($bt_Mn_OpenFolder, $GUI_ENABLE)
  357.                     $i_Response = MsgBox(4 + 64 + 256 + 8192, $s_Title, 'Download complete!' & @LF & _
  358.                             'Would you like to run the installer now?')
  359.                     If $i_Response = 6 Then
  360.                         _Start('"' & $s_DownPath & '"')
  361.                         Exit
  362.                     EndIf
  363.                 EndIf
  364.             EndIf
  365.             $i_DnInitiated = 0
  366.         EndIf
  367.     EndIf
  368.     If $a_GMsg[1] = $gui_Main Then
  369.         Select
  370.             ; Radio buttons
  371.             Case $a_GMsg[0] = $ra_Mn_DoneRun
  372.                 RegWrite($s_Au3UpReg, 'DoneOption', 'REG_SZ', 'Run')
  373.             Case $a_GMsg[0] = $ra_Mn_DoneNotify
  374.                 RegWrite($s_Au3UpReg, 'DoneOption', 'REG_SZ', 'Notify')
  375.                 ; Download buttons
  376.             Case $a_GMsg[0] = $bt_Mn_ReleaseDl
  377.                 $tmp = StringInStr($s_ReleaseFile, '/', 0, -1)
  378.                 $s_DefFileName = StringTrimLeft($s_ReleaseFile, $tmp)
  379.                 $i_DownSize = $i_ReleaseSize
  380.                 _DownloadFile($s_ReleaseFile, 'autoit-v3-setup.exe')
  381.             Case $a_GMsg[0] = $bt_Mn_BetaDl
  382.                 $tmp = StringInStr($s_BetaFile, '/', 0, -1)
  383.                 $s_DefFileName = StringTrimLeft($s_BetaFile, $tmp)
  384.                 $i_DownSize = $i_BetaSize
  385.                 _DownloadFile($s_BetaFile, 'autoit-v' & $s_LatestBetaVer & '.exe')
  386.             Case $a_GMsg[0] = $bt_Mn_PreBetaDl
  387.                 $tmp = StringInStr($s_PreBetaFile, '/', 0, -1)
  388.                 $s_DefFileName = StringTrimLeft($s_PreBetaFile, $tmp)
  389.                 $i_DownSize = $i_PreBetaSize
  390.                 _DownloadFile($s_PreBetaFile, 'autoit-v' & $s_PreBetaVer & '.exe')
  391.                 ; Download page "hyperlinks"
  392.             Case $a_GMsg[0] = $lb_Mn_ReleasePage
  393.                 _Start($s_ReleasePage)
  394.             Case $a_GMsg[0] = $lb_Mn_BetaPage
  395.                 _Start($s_BetaPage)
  396.             Case $a_GMsg[0] = $lb_Mn_PreBetaPage
  397.                 _Start($s_PreBetaPage)
  398.                 ; Open buttons
  399.             Case $a_GMsg[0] = $bt_Mn_OpenFile
  400.                 _Start('"' & $s_DownPath & '"')
  401.                 Exit
  402.             Case $a_GMsg[0] = $bt_Mn_OpenFolder
  403.                 _Start('"' & EnvGet('windir') & '\explorer.exe" /select,"' & $s_DownPath & '"')
  404.                 Exit
  405.                 ; Menu items
  406.             Case $a_GMsg[0] = $me_Mn_Proxy
  407.                 If BitAnd(GUICtrlRead($me_Mn_Proxy), $GUI_CHECKED) = $GUI_CHECKED Then
  408.                     GUICtrlSetState($me_Mn_Proxy, $GUI_UNCHECKED)
  409.                     HttpSetProxy(0)
  410.                 Else
  411.                     GUICtrlSetState($me_Mn_Proxy, $GUI_CHECKED)
  412.                     HttpSetProxy(1)
  413.                 EndIf
  414.             Case $a_GMsg[0] = $me_Mn_VisitSite
  415.                 _Start('http://www.autoitscript.com')
  416.             Case $a_GMsg[0] = $me_Mn_About
  417.                 GUISetState(@SW_SHOW, $gui_About)
  418.                 ; Close buttons
  419.             Case $a_GMsg[0] = $bt_Mn_Close
  420.                 _CancelDownload()
  421.             Case $a_GMsg[0] = $GUI_EVENT_CLOSE
  422.                 _CancelDownload(1)
  423.         EndSelect
  424.     ElseIf $a_GMsg[1] = $gui_About Then
  425.         Select
  426.             Case $a_GMsg[0] = $lb_Ab_VisitSite
  427.                 _Start('http://www.autoitscript.com')
  428. ;         Case $a_GMsg[0] = $lb_Ab_ContactAuthor
  429. ;            _Start('"mailto:rksaunders@gmail.com?Subject=AutoIt3 Update Utility"')
  430.             Case $a_GMsg[0] = $GUI_EVENT_CLOSE Or $a_GMsg[0] = $bt_Ab_Close
  431.                 GUISetState(@SW_HIDE, $gui_About)
  432.         EndSelect
  433.     EndIf
  434. WEnd
  435.  
  436.  
  437. ; ========================================
  438. ; Function Declarations
  439. ; ========================================
  440. ; App. specific functions
  441. Func _DownloadFile($s_DownUrl, $s_DownName)
  442.     $s_DownTemp = @TempDir & '\' & $s_DownName
  443.     InetGet($s_DownUrl, $s_DownTemp, 1, 1)
  444.     $s_DownPath = FileSaveDialog('Save As', $s_DefDownDir, 'Executables (*.exe)', 16, $s_DownName)
  445.     If Not @error Then
  446.         If Not (StringRight($s_DownPath, 4) = '.exe') Then
  447.             $s_DownPath = $s_DownPath & '.exe'
  448.         EndIf
  449.         $tmp = StringInStr($s_DownPath, '\', 0, -1)
  450.         $s_DownFolder = StringLeft($s_DownPath, $tmp)
  451.         RegWrite($s_Au3UpReg, 'DownloadDir', 'REG_SZ', $s_DownFolder)
  452.         GUICtrlSetData($lb_Mn_DwnToTxt, _ClipPath($s_DownPath, 55))
  453.         GUICtrlSetData($lb_Mn_Progress, 'Download Progress: Calculating...')
  454.         _GuiCtrlGroupSetState($a_DownButtons, $GUI_HIDE)
  455.         _GuiCtrlGroupSetState($a_DownButtons, $GUI_DISABLE)
  456.         _GuiCtrlGroupSetState($a_DownDisplay, $GUI_SHOW)
  457.         If $s_PreBetaVer <> '' Then
  458.             GUICtrlSetPos($bt_Mn_Close, 265 + 175, 275, 75, 25)
  459.         Else
  460.             GUICtrlSetPos($bt_Mn_Close, 265, 275, 75, 25)
  461.         EndIf
  462.         GUICtrlSetData($bt_Mn_Close, 'Cancel')
  463.         $i_DnInitiated = 1
  464.     Else
  465.         InetGet('abort')
  466.         FileDelete($s_DownTemp)
  467.     EndIf
  468. EndFunc   ;==>_DownloadFile
  469.  
  470.  
  471. Func _CancelDownload($i_Flag = 0)
  472.     If $i_DnInitiated Then
  473.         $i_Response = MsgBox(4 + 64 + 256 + 8192, $s_Title, 'Resuming is not possible.' & @LF & _
  474.                 'Your download will be lost.' & @LF & _
  475.                 'Continue?')
  476.         If $i_Response = 6 Then
  477.             $i_DnInitiated = 0
  478.             InetGet('abort')
  479.             FileDelete($s_DownTemp)
  480.             If $i_Flag = 1 Then
  481.                 Exit
  482.             EndIf
  483.             _GuiCtrlGroupSetState($a_DownDisplay, $GUI_HIDE)
  484.             GUICtrlSetData($bt_Mn_Close, '&Close')
  485.             If $s_PreBetaVer <> '' Then
  486.                 GUICtrlSetPos($bt_Mn_Close, 10, 275, 330 + 175, 25)
  487.             Else
  488.                 GUICtrlSetPos($bt_Mn_Close, 10, 275, 330, 25)
  489.             EndIf
  490.             GUICtrlSetData($pg_Mn_Progress, 0)
  491.             _GuiCtrlGroupSetState($a_DownButtons, $GUI_SHOW)
  492.             _GuiCtrlGroupSetState($a_DownButtons, $GUI_ENABLE)
  493.         EndIf
  494.     Else
  495.         Exit
  496.     EndIf
  497. EndFunc   ;==>_CancelDownload
  498.  
  499.  
  500. Func _LoadUpdateData()
  501.     Global $s_ReleaseVer, $s_ReleaseFile, $s_ReleasePage, $i_ReleaseSize, $i_ReleaseDate
  502.     Global $s_LatestBetaVer, $s_BetaFile, $s_BetaPage, $i_BetaSize, $i_BetaDate
  503.     Global $s_PreBetaVer, $s_PreBetaFile, $s_PreBetaPage, $i_PreBetaSize, $i_PreBetaDate
  504.     $s_ReleaseVer = IniRead($s_DatFile_Local, 'AutoIt', 'version', 'Error reading file')
  505.     $s_ReleaseFile = IniRead($s_DatFile_Local, 'AutoIt', 'setup', '')
  506.     $s_ReleasePage = IniRead($s_DatFile_Local, 'AutoIt', 'index', 'http://www.autoitscript.com')
  507.     $i_ReleaseSize = IniRead($s_DatFile_Local, 'AutoIt', 'filesize', 0)
  508.     $i_ReleaseDate = IniRead($s_DatFile_Local, 'AutoIt', 'filetime', 0)
  509.     $s_LatestBetaVer = IniRead($s_DatFile_Local, 'AutoItBeta', 'version', 'Error reading file')
  510.     $s_BetaFile = IniRead($s_DatFile_Local, 'AutoItBeta', 'setup', '')
  511.     $s_BetaPage = IniRead($s_DatFile_Local, 'AutoItBeta', 'index', 'http://www.autoitscript.com')
  512.     $i_BetaSize = IniRead($s_DatFile_Local, 'AutoItBeta', 'filesize', 0)
  513.     $i_BetaDate = IniRead($s_DatFile_Local, 'AutoItBeta', 'filetime', 0)
  514.     $s_PreBetaVer = IniRead($s_DatFile_Local, 'AutoItPreBeta', 'version', '')
  515.     $s_PreBetaFile = IniRead($s_DatFile_Local, 'AutoItPreBeta', 'setup', '')
  516.     $s_PreBetaPage = IniRead($s_DatFile_Local, 'AutoItPreBeta', 'index', 'http://www.autoitscript.com')
  517.     $i_PreBetaSize = IniRead($s_DatFile_Local, 'AutoItPreBeta', 'filesize', 0)
  518.     $i_PreBetaDate = IniRead($s_DatFile_Local, 'AutoItPreBeta', 'filetime', 0)
  519.     FileDelete($s_DatFile_Local)
  520. EndFunc   ;==>_LoadUpdateData
  521.  
  522.  
  523. ; Utility functions
  524. Func _Start($s_StartPath)
  525.     If @OSTYPE = 'WIN32_NT' Then
  526.         $s_StartStr = @ComSpec & ' /c start "" '
  527.     Else
  528.         $s_StartStr = @ComSpec & ' /c start '
  529.     EndIf
  530.     Run($s_StartStr & $s_StartPath, '', @SW_HIDE)
  531. EndFunc   ;==>_Start
  532.  
  533.  
  534. Func _GuiCtrlGroupSetState(ByRef $a_GroupArray, $i_State)
  535.     For $i = 1 To $a_GroupArray[0]
  536.         GUICtrlSetState($a_GroupArray[$i], $i_State)
  537.     Next
  538. EndFunc   ;==>_GuiCtrlGroupSetState
  539.  
  540.  
  541. Func _ClipPath($s_Path, $i_ClipLen)
  542.     Local $i_Half, $s_Left, $s_Right
  543.     If StringLen($s_Path) > $i_ClipLen Then
  544.         $i_Half = Int($i_ClipLen / 2)
  545.         $s_Left = StringLeft($s_Path, $i_Half)
  546.         $s_Right = StringRight($s_Path, $i_Half)
  547.         $s_Path = $s_Left & '...' & $s_Right
  548.     EndIf
  549.     Return $s_Path
  550. EndFunc   ;==>_ClipPath
  551.  
  552.  
  553. Func _NumSuffix($i_Num)
  554.     Local $s_Num
  555.     Switch Int($i_Num)
  556.         Case 1, 21, 31
  557.             $s_Num = Int($i_Num) & 'st'
  558.         Case 2, 22
  559.             $s_Num = Int($i_Num) & 'nd'
  560.         Case 3, 23
  561.             $s_Num = Int($i_Num) & 'rd'
  562.         Case Else
  563.             $s_Num = Int($i_Num) & 'th'
  564.     EndSwitch
  565.     Return $s_Num
  566. EndFunc   ;==>_NumSuffix
  567.  
  568.  
  569. Func _FriendlyDate($s_Date)
  570.     Local $a_Months = StringSplit('January,February,March,April,May,June,July,August,September,October,November,December', ',')
  571.     Local $s_Year, $s_Month, $s_Day
  572.     $s_Year = StringLeft($s_Date, 4)
  573.     $s_Month = StringMid($s_Date, 5, 2)
  574.     $s_Month = $a_Months[Int(StringMid($s_Date, 5, 2)) ]
  575.     $s_Day = StringMid($s_Date, 7, 2)
  576.     $s_Day = _NumSuffix(StringMid($s_Date, 7, 2))
  577.     Return $s_Month & ' ' & $s_Day & ', ' & $s_Year
  578. EndFunc   ;==>_FriendlyDate
  579.  
  580.  
  581. Func _StringInArray($a_Array, $s_String)
  582.     Local $i_ArrayLen = UBound($a_Array) - 1
  583.     For $i = 0 To $i_ArrayLen
  584.         If $a_Array[$i] = $s_String Then
  585.             Return $i
  586.         EndIf
  587.     Next
  588.     SetError(1)
  589.     Return 0
  590. EndFunc   ;==>_StringInArray
  591.  
  592.  
  593. Func _CompareVersions($s_Vers1, $s_Vers2, $i_ReturnFlag = 0)
  594.     If $s_Vers1 = '' Then Return 0
  595.     Local $i, $i_Vers1, $i_Vers2, $i_Top
  596.     Local $a_Vers1 = StringSplit($s_Vers1, '.')
  597.     Local $a_Vers2 = StringSplit($s_Vers2, '.')
  598.     $i_Top = $a_Vers1[0]
  599.     If $a_Vers1[0] < $a_Vers2[0] Then
  600.         $i_Top = $a_Vers2[0]
  601.     EndIf
  602.     For $i = 1 To $i_Top
  603.         $i_Vers1 = 0
  604.         $i_Vers2 = 0
  605.         If $i <= $a_Vers1[0] Then
  606.             $i_Vers1 = Number($a_Vers1[$i])
  607.         EndIf
  608.         If $i <= $a_Vers2[0] Then
  609.             $i_Vers2 = Number($a_Vers2[$i])
  610.         EndIf
  611.         If $i_Vers1 > $i_Vers2 Then
  612.             $v_Return = 1
  613.             ExitLoop
  614.         ElseIf $i_Vers1 < $i_Vers2 Then
  615.             $v_Return = 0
  616.             ExitLoop
  617.         Else
  618.             $v_Return = -1
  619.         EndIf
  620.     Next
  621.     If $i_ReturnFlag Then
  622.         Select
  623.             Case $v_Return = -1
  624.                 SetError(1)
  625.                 Return 0
  626.             Case $v_Return = 1
  627.                 Return $s_Vers1
  628.             Case $v_Return = 0
  629.                 Return $s_Vers2
  630.         EndSelect
  631.     ElseIf $v_Return = -1 Then
  632.         SetError(1)
  633.         Return 0
  634.     Else
  635.         Return $v_Return
  636.     EndIf
  637. EndFunc   ;==>_CompareVersions
  638.  
  639.  
  640. Func _Status($s_MainText, $s_SubText = '', $i_BytesRead = -1, $i_DownSize = -1)
  641.     Global $i_ProgOn
  642.     Global $i_StatusPercent
  643.     If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Then
  644.         If $s_SubText <> '' Then
  645.             $s_SubText = @LF & $s_SubText
  646.         EndIf
  647.         If $i_BytesRead = -1 Then
  648.             TrayTip($s_Title, $s_MainText & $s_SubText, 10, 16)
  649.         Else
  650.             $s_DownStatus = Round($i_BytesRead / 1024) & ' of ' & Round($i_DownSize / 1024) & ' KB'
  651.             TrayTip($s_Title, $s_MainText & $s_SubText & @LF & $s_DownStatus, 10, 16)
  652.         EndIf
  653.     Else
  654.         If Not $i_ProgOn Then
  655.             ProgressOn($s_Title, $s_MainText, $s_SubText, -1, -1, 2 + 16)
  656.             $i_ProgOn = 1
  657.         Else
  658.             If $i_BytesRead = -1 Then
  659.                 ProgressSet($i_StatusPercent, $s_SubText, $s_MainText)
  660.             Else
  661.                 $s_DownStatus = 'Downloading ' & Round($i_BytesRead / 1024) & ' of ' & Round($i_DownSize / 1024) & ' KB'
  662.                 $i_StatusPercent = Round($i_BytesRead / $i_DownSize * 100)
  663.                 ProgressSet($i_StatusPercent, $s_DownStatus, $s_MainText)
  664.             EndIf
  665.         EndIf
  666.     EndIf
  667. EndFunc   ;==>_Status
  668.